import os
import hashlib
from pathlib import Path
from typing import Union

def calculate_checksum(file_path: Union[str, Path]) -> str:
    """计算文件的SHA256校验和"""
    sha256_hash = hashlib.sha256()
    with open(file_path, "rb") as f:
        for byte_block in iter(lambda: f.read(4096), b""):
            sha256_hash.update(byte_block)
    return sha256_hash.hexdigest()

def get_file_size(file_path: Union[str, Path]) -> int:
    """获取文件大小"""
    return os.path.getsize(file_path)

def ensure_dir(path: Union[str, Path]) -> Path:
    """确保目录存在"""
    path = Path(path)
    path.mkdir(parents=True, exist_ok=True)
    return path

def clean_path(path: Union[str, Path]) -> Path:
    """清理并规范化路径"""
    return Path(path).resolve()